<template>
  <div
    class="scroll-container"
    ref="scrollContainer"
    @wheel.prevent="handleScroll"
  >
    <div
      class="scroll-wrapper"
      ref="scrollWrapper"
      :style="{ top: top + 'px' }"
    >
      <slot></slot>
    </div>
  </div>
</template>
<script>
const delta = 15;
import Cookies from "js-cookie";
export default {
  name: "scrollBar",
  //暴露reload方法
  inject: ["reload"],
  data() {
    return {
      top: 0,
      language: "",
    };
  },
  created() {},
  methods: {
    handleScroll(e) {
      const eventDelta = e.wheelDelta || -e.deltaY * 3;
      const $container = this.$refs.scrollContainer;
      const $containerHeight = $container.offsetHeight;
      const $wrapper = this.$refs.scrollWrapper;
      const $wrapperHeight = $wrapper.offsetHeight;
      if (eventDelta > 0) {
        this.top = Math.min(0, this.top + eventDelta);
      } else {
        if ($containerHeight - delta < $wrapperHeight) {
          if (this.top < -($wrapperHeight - $containerHeight + delta)) {
            this.top = this.top;
          } else {
            this.top = Math.max(
              this.top + eventDelta,
              $containerHeight - $wrapperHeight - delta
            );
          }
        } else {
          this.top = 0;
        }
      }
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "../../styles/variables.scss";
@media screen and (min-width: 769px) {
  .language-container {
    display: none;
  }
}
/* 响应式布局 */
@media screen and (max-width: 768px) {
  .language-container {
    position: absolute;
    bottom: 80px;
    left: 50px;
  }
  .info1 {
    display: inline-block;
    font-size: 22px;
    margin-left: 15px;
  }
  .language-dropdown {
    width: 180px;
    margin-left: 22px;
  }
  .el-icon-caret-top {
    margin-left: 15px;
  }
  .language-avatar {
    display: inline-block;
    margin-bottom: -3px;
  }
  .size {
    font-size: 20px;
  }
  #spanSty {
    color: #e60023 !important;
  }
}
.scroll-container {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: $menuBg;
  .scroll-wrapper {
    position: absolute;
    width: 100% !important;
  }
}
</style>

